<?php

	if( substr_count($_SERVER['REDIRECT_URL'],'..') > 0 ){
		echo 'File not found : /resource/'.$resourcePath;
	}else if( substr_count($_SERVER['REDIRECT_URL'],'/') > 1 ){
		$resourcePath = substr($_SERVER['REDIRECT_URL'], strpos(substr( $_SERVER['REDIRECT_URL'], 1), '/')+2);
		foreach ( array_keys(Register::getPlugins()) as $plugin ){
			if($plugin['Status']!=='INSTALLED'){
				$realFilepath = PLUGINS_PATH . '/' . $plugin . '/resource/' .$resourcePath;
				if( is_file($realFilepath) ){
					//load file
  					$filename = iconv( "UTF-8", "Big5", substr( $realFilepath , strrpos($realFilepath,'/')+1 ) );
					$size = filesize($realFilepath);
					//Set Http Herder
    				Header('Content-Description: File Transfer');
    				Header('Content-Length: '.$size);
    				Header('Content-type: application/download');
    				Header('Content-Disposition-type: attachment');
    				Header('Content-Disposition: filename='.$filename);
    				Header('Content-Transfer-Encoding: binary');
    				//open file and send
    				$fp = fopen($realFilepath,"rb"); 
    				fpassthru($fp);
    				fclose($fp);
					exit(0);
				}
			}
		}
		echo 'File not found : /resource/'.$resourcePath;
	}
	exit(0);
	
?>
